import GlobalUtil from './GlobalUtil'
function getPermission(): number[] {
  
  const arr: any = GlobalUtil.getSessionStorage('permissionArr') || []
  
  return arr
}
// 判断权限是否存在 --在则返回true 不在返回false  在login.vue中进行获取
export function verifyPermission(viewPermission: number[] | undefined) {

  if (!viewPermission) return true
  
  const arr = getPermission()
  
  for (let j of viewPermission) {

    for (let i of arr) {

      
      if (i == j) return true

    }
  }
  return false
}
//获取登录信息
function getLoginInfo() {
  return GlobalUtil.getSessionStorage('loginInfo');
}
//设置登录信息
function setLoginInfo<T>(data: T) {
  // @ts-ignore
  GlobalUtil.setSessionStorage('loginInfo', data);
}
export function setPermission(data: number[]) {
  console.log(data);
  
  GlobalUtil.setSessionStorage('permissionArr', data)
}

// eslint-disable-next-line import/no-anonymous-default-export
export default {
  verifyPermission,
  setPermission,
  getLoginInfo,
  setLoginInfo,
  
}